<template>
  <!-- 放置一个图标 -->
  <div>
    <!-- svg-icon组件, 配置icon-class属性, 配置成svg的文件名即可 -->
    <svg-icon
      v-if="!isFullScreen"
      icon-class="fullscreen"
      class="fullscreen"
      @click="toggleFullScreen"
    />
    <svg-icon
      v-else
      icon-class="exit-fullscreen"
      class="fullscreen"
      @click="toggleFullScreen"
    />
  </div>
</template>

<script>
export default {
  name: "ScreenFull",
  data() {
    return {
      isFullScreen: false, // 默认不全屏
    };
  },
  methods: {
    // 全屏切换
    toggleFullScreen() {
      // 是全屏
      if (this.isFullScreen) {
        // 取消全屏
        document.exitFullscreen();
      } else {
        // 显示全屏
        document.documentElement.requestFullscreen();
      }
      // 自身取反，实现开关效果
      this.isFullScreen = !this.isFullScreen;
    },
  },
};
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  fill: #fff;
  cursor: pointer;
}
</style>
